package com.github.lyd.admin.provider.controller;

import com.github.lyd.admin.provider.entity.AspNetUserLoginsEntity;
import com.github.lyd.admin.provider.service.AspNetUserLoginsService;
import com.github.lyd.admin.provider.utils.PageUtils;
import com.github.lyd.admin.provider.utils.R;
import com.github.lyd.admin.provider.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 用户登陆渠道表
 *
 * @author yaowu
 * @email toyaowu@163.com
 * @date 2019-01-20 11:08:15
 */
@RestController
@RequestMapping("weixin/aspnetuserlogins")
public class AspNetUserLoginsController {
    @Autowired
    private AspNetUserLoginsService aspNetUserLoginsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = aspNetUserLoginsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{loginProvider}")
    public R info(@PathVariable("loginProvider") String loginProvider){
        AspNetUserLoginsEntity aspNetUserLogins = aspNetUserLoginsService.selectById(loginProvider);

        return R.ok().put("aspNetUserLogins", aspNetUserLogins);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AspNetUserLoginsEntity aspNetUserLogins){
        aspNetUserLoginsService.insert(aspNetUserLogins);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AspNetUserLoginsEntity aspNetUserLogins){
        ValidatorUtils.validateEntity(aspNetUserLogins);
        aspNetUserLoginsService.updateAllColumnById(aspNetUserLogins);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] loginProviders){
        aspNetUserLoginsService.deleteBatchIds(Arrays.asList(loginProviders));

        return R.ok();
    }

}
